package com.sh.foa.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sh.foa.model.VoTalkData;
import com.sh.foa.service.TalkService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
@Controller
@RequestMapping(value ="talk")
@Api(tags = {"foa"})
public class TalkController {
	private TalkService talkService;
	@Autowired
	public void setTalkService(TalkService talkService) {
		this.talkService = talkService;
	}
	
	@ResponseBody
	@RequestMapping(value = "sendMsg", method = {RequestMethod.POST,RequestMethod.GET})
	@ApiOperation(httpMethod = "POST,GET", value = "发送消息", notes = "用户发言")//swagger 当前接口注解
	@ApiImplicitParams({
		  @ApiImplicitParam(name="idUser",value="用户id",dataType="string",required=true, paramType = "query",example="2c46b9afa74f467799371e37b8e90b6d")})
	//swagger返回值注解
	@ApiResponses(value = {
		@ApiResponse(code = 500, message = "系统错误"),
	        @ApiResponse(code = 200, message = "成功,返回格式：{code:0,msg:'',data[{}]},data中的属性参照下方Model", response = void.class) })		
	public List<Map<String, String>> sendMsg(HttpServletRequest request, HttpServletResponse response) {
//		com.data.core.common.util.LogUtil.getAppDebugLog().debug("sysUser.login");
		com.sh.common.LogUtil.getAppDebugLog().debug("talk.sendMsg");
//		String strAdd = request.getParameter("dataAdd");
//		String strUpdate = request.getParameter("dataUpdate");
//		String strVoBean = request.getParameter("dataVoBeanType");
//		String strMenuNameMain = request.getParameter("dataMenuNameMain");
//		String strMenuCodeMain = request.getParameter("dataMenuCodeMain");
//		String strMenuNameChild = request.getParameter("dataMenuNameChild");
//		String strMenuCodeChild = request.getParameter("dataMenuCodeChild");
		//class.getClass(strVoBean)
		List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
		String idUser = request.getParameter("idUser");
		String content = request.getParameter("content");
		String idTalk = request.getParameter("idTalk");
		try {
			//response.getWriter().write("{\"success\":\"true\"}");
			VoTalkData vtd = new VoTalkData();
			vtd.setNidTalk(Long.valueOf(idTalk));
			vtd.setTalkContent(content);
			VoTalkData as = talkService.answer(vtd);
			Map<String, String> smap = new HashMap<String, String>();
			smap.put("data",  as.getTalkContent());
			smap.put("code", "1");
			ret.add(smap);
		} catch (Exception e) {
			com.sh.common.LogUtil.getAppDebugLog().error("sendMsg失败", e);
			Map<String, String> smap = new HashMap<String, String>();
			smap.put("data",  "哈哈，电脑傻了，乱了:" + e.getMessage());
			smap.put("code", "0");
			ret.add(smap);
		}
		
		return ret;
	}
}
